package com.easylinkin.linkappapi.alarm.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easylinkin.linkappapi.alarm.entity.AlarmPersonContact;
import com.easylinkin.linkappapi.alarm.mapper.AlarmPersonContactMapper;
import com.easylinkin.linkappapi.alarm.service.AlarmPersonContactService;
import com.easylinkin.linkappapi.security.context.LinkappUserContextProducer;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class AlarmPersonContactServiceImpl extends ServiceImpl<AlarmPersonContactMapper, AlarmPersonContact> implements AlarmPersonContactService {
    @Resource
    private LinkappUserContextProducer linkappUserContextProducer;

    /**
     * 获得告警联系人列表信息
     * @param page
     * @param alarmPersonContact
     * @return
     */
    @Override
    public IPage<AlarmPersonContact> getAlarmPersonContacts(Page page, AlarmPersonContact alarmPersonContact) {
        alarmPersonContact.setTenantId(linkappUserContextProducer.getNotNullCurrent().getTenantId());
        return baseMapper.getAlarmPersonContacts(page, alarmPersonContact);
    }

    @Override
    public List<AlarmPersonContact> getAlarmPersonContacts(AlarmPersonContact alarmPersonContact) {
        alarmPersonContact.setTenantId(linkappUserContextProducer.getNotNullCurrent().getTenantId());
        return baseMapper.getAlarmPersonContacts(alarmPersonContact);
    }

    /**
     * 根据id删除告警联系人
     * @param id
     * @return
     */
    @Override
    public boolean deleteAlarmPersonContactById(String id) {
        baseMapper.deleteById(id);
        return true;
    }

    /**
     * 新增告警联系人
     * @param alarmPersonContact
     * @return
     */
    @Override
    public boolean addAlarmPersonContact(AlarmPersonContact alarmPersonContact) {
        alarmPersonContact.setCreateTime(new Date());
        alarmPersonContact.setModifyTime(new Date());
        alarmPersonContact.setUserId(linkappUserContextProducer.getNotNullCurrent().getId().toString());
        alarmPersonContact.setTenantId(linkappUserContextProducer.getNotNullCurrent().getTenantId());
        baseMapper.insert(alarmPersonContact);
        return true;
    }

    /**
     * 更新告警联系人
     * @param alarmPersonContact
     * @return
     */
    @Override
    public boolean updateAlarmPersonContact(AlarmPersonContact alarmPersonContact) {
        alarmPersonContact.setModifyTime(new Date());
        baseMapper.updateById(alarmPersonContact);
        return true;
    }
}
